package com.leyou.item.controller;

import com.leyou.common.utils.BeanHelper;
import com.leyou.dto.CategoryDto;
import com.leyou.item.entity.Category;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @version V1.0
 * @author: Ljxpa
 * @date: 2020/03/03 18:14
 * @description:
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

	@Autowired
	private CategoryService categoryService;

	@GetMapping("/of/parent")
	public ResponseEntity<List<Category>> queryParentCategory(Long pid) {
		List<Category> list = categoryService.queryParentCategory(pid);
		return ResponseEntity.ok(list);
	}

	@GetMapping("/of/brand")
	public ResponseEntity<List<Category>> queryCategoriesByBrandId(@RequestParam("id") Long id) {
		List<Category> list = categoryService.queryCategoriesByBrandId(id);
		return ResponseEntity.ok().body(list);
	}

	@GetMapping("/list")
	public ResponseEntity<List<CategoryDto>> queryCategoriesByCids(@RequestParam("cids") List<Long> cids) {
		return ResponseEntity.ok(BeanHelper.copyWithCollection(categoryService.queryCategoriesByCids(cids), CategoryDto.class));
	}

	@GetMapping("/list/cid3")
	public ResponseEntity<List<CategoryDto>> queryCategoriesByCid3(@RequestParam("cid3") Long cid3){
		List<CategoryDto> categoryDtoList = categoryService.queryCategoriesByCid3(cid3);
		return ResponseEntity.ok(categoryDtoList);
	}

}
